﻿using BUS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EC21_EDiamond
{
    public partial class ThuongHieu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rpDanhMuc.DataSource = DanhMucBUS.Ds_DanhMuc();
                rpDanhMuc.DataBind();
                if (Request.QueryString["id"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    string id = Request.QueryString["id"].ToString();
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = SanPhamBUS.Ds_SanPhamTheoTH(Int32.Parse(id)).DefaultView;
                    pds.AllowPaging = true;
                    pds.PageSize = 6;
                    int numPage = pds.PageCount;
                    int currentPage;
                    if (Request.QueryString["page"] != null)
                    {
                        currentPage = Int32.Parse(Request.QueryString["page"]);
                    }
                    else
                    {
                        currentPage = 1;
                    }
                    pds.CurrentPageIndex = currentPage - 1;
                    lbTrangHt.Text = currentPage.ToString();
                    lbTongTrang.Text = pds.PageCount.ToString();
                    string linkDau = Request.CurrentExecutionFilePath + "?id=" + id;
                    if (!pds.IsFirstPage)
                        hplPrevev.NavigateUrl = linkDau + "?page=" + Convert.ToString(currentPage - 1);
                    else
                    {
                        hplPrevev.Visible = false;
                    }
                    if (!pds.IsLastPage)
                        hplNext.NavigateUrl = linkDau + "?page=" + Convert.ToString(currentPage + 1);
                    else
                    {

                        hplNext.Visible = false;
                    }
                    rpSanPham.DataSource = pds;
                    rpSanPham.DataBind();
                    lbSoSp.Text = pds.Count.ToString();
                    lbDanhMuc.Text = DanhMucBUS.TenDanhMuc(Int32.Parse(id));
                    lbDanhMuc1.Text = lbDanhMuc.Text;
                    lbTrangHt1.Text = lbTrangHt.Text;
                }
            }
        }
    }
}